package com.qf.test.test.service;

import com.qf.test.test.mapper.UserMapper;
import com.qf.test.test.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("service1")
public class UserServiceImpl implements UserService {
    //需要被注入的用户dao全局对象
    @Autowired
    private UserMapper userMapper;
    //从jdbc,properties文件中跟胡key拿value值
    @Value("$(jdbc.url)")
    private String url;
    @Value("$jdbc.username")
    private String username;

    public List<User> findAll() {
        //直接用注入的UserMapper对象

        System.out.println("=====url==========" + url);
        System.out.println("=====username==========" + username);
        //直接注入的UserMapper对象
        List<User> list = userMapper.findUserAll();
        return list;

    }

    @Transactional
    public void updateUset(User user) {
        userMapper.updateUser( user);
        //演示拥有事务中的操作如果有异常 是否会出现回滚
        int i=1/0;
    }
}
